<?php

$username = Path::get('//user/user_login', 'flow');
$user_password = Path::get('//user/user_password', 'flow');
$user_id = Path::get('//user/user_id', 'flow');
$roles = Path::get('//role/name', 'flow');


// Remove duplicate roles
if(is_array($roles)) { 
	$tmparr = array_unique($roles);
	
	$i=0;
	
	foreach ($tmparr as $v) {
		$newarr[$i] = $v;
		$i++;
	}  

} else { 
	$newarr=$roles;
}


$auth = &new Auth();
        
if(!$auth->registerUser($newarr))
{
    trigger_error(Error::getError(). ' in login.php', WARNING);         
}


$auth->setSessionData("user_id", $user_id);
$auth->setSessionData("user_name", $username);


//go back where we were called from
$redirect = Path::get('//_post/redirect', 'flow');
if(isset($_SESSION['NX_AUTH']['requestedUrl']) && (!$_SESSION['NX_AUTH']['requestedUrl']=="")) { 
    $redirect = $_SESSION['NX_AUTH']['requestedUrl'];	
} else { 
    $redirect = Config::get("//build/default");
}


header("Location: $redirect");

?>